<?php

// app/Http/Middleware/Base.php

namespace App\Http\Middleware;


class Base
{

     /**
     * 操作成功返回
     */
    protected function success($data=[], $msg = '操作成功', $code = 200)
    {
        if(empty($data)){
            $data=[];
        }
        $alert=[
            'code'    => $code,
            'message' => $msg,
            'data'    => $data
        ];
        echo json_encode($alert);
        exit;

    }

     /**
     * 操作失败返回
     */
    protected function error($msg = '操作失败', $code = 0 , $data=[])
    {
        if(empty($data)){
            $data=[];
        }
        $alert=[
            'code'    => $code,
            'message' => $msg,
            'data'    => $data
        ];
        echo json_encode($alert);
        exit;

    }

}
